import 'package:beamer/beamer.dart';
import 'package:flutter/material.dart';

class AppBarWidget extends StatefulWidget implements PreferredSizeWidget {
  final String imgPath;
  final String title;
  final bool? turnIcon;

  const AppBarWidget({
    super.key,
    required this.imgPath,
    required this.title,
    this.turnIcon = false,
  });

  @override
  State<AppBarWidget> createState() => _MyWidgetState();

  @override
  // TODO: implement preferredSize
  Size get preferredSize => const Size(double.infinity, kToolbarHeight);
}

class _MyWidgetState extends State<AppBarWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: MediaQuery.of(context).size.width + kToolbarHeight,
      decoration: BoxDecoration(
        color: Colors.white,
        image: DecorationImage(
          image: AssetImage(widget.imgPath),
          fit: BoxFit.cover,
        ),
      ),
      child: SafeArea(
        child: Stack(
          children: [
            Center(
              child: Text(
                widget.title,
                style: const TextStyle(fontSize: 16.0, color: Colors.white),
              ),
            ),
            widget.turnIcon != false
                ? Positioned(
                    top: 0,
                    left: 12,
                    bottom: 0,
                    child: GestureDetector(
                      onTap: () {
                        Beamer.of(context).beamBack();
                      },
                      child: const Icon(
                        Icons.arrow_back_ios_sharp,
                        color: Colors.white,
                      ),
                    ))
                : const SizedBox()
          ],
        ),
      ),
    );
  }
}
